package cn.com.nes.site.controller.agent;

import cn.com.nes.common.web.CommonResult;
import cn.com.nes.mybatis.agent.agent.entity.AgentGrantType;
import cn.com.nes.site.controller.agent.vo.AgentGrantPageVO;
import cn.com.nes.site.controller.agent.vo.AgentGrantQueryVO;
import cn.com.nes.site.controller.agent.vo.QueryAgentSupplierIdsVO;
import cn.com.nes.site.controller.agent.vo.SingleAgentGrantSaveVO;
import cn.com.nes.site.modules.agent.grant.AgentGrant;
import cn.com.nes.site.service.agent.bo.AgentGrantPageBO;
import cn.com.nes.site.service.agent.bo.AgentGrantQueryBO;
import cn.com.nes.site.service.agent.bo.AgentGrantSaveBO;
import cn.com.nes.site.service.agent.dto.AgentGrantDTO;
import cn.com.nes.site.service.agent.dto.AgentGrantDetailDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = {"渠道管理-渠道授权"})
@Slf4j
@RestController
@RequestMapping("/v2/agent/grant")
public class AgentGrantController {

    @Resource
    private AgentGrant agentGrant;

    @ApiOperation("渠道授权分页查询")
    @RequestMapping(value = "agentGrantPage", method = RequestMethod.GET)
    public CommonResult<AgentGrantDTO> agentGrantPage(@Validated AgentGrantPageVO agentGrantPageVO) throws Exception {
        return CommonResult.page(agentGrant.getPage(agentGrantPageVO.convertToBo(AgentGrantPageBO.class)));
    }


    @ApiOperation("渠道授权详情查询")
    @RequestMapping(value = "agentGrantDetail", method = RequestMethod.GET)
    public CommonResult<AgentGrantDetailDTO> agentGrantDetail(@Validated AgentGrantQueryVO agentGrantQueryVO) throws Exception {
        return CommonResult.data(agentGrant.getDetail(agentGrantQueryVO.convertToBo(AgentGrantQueryBO.class)));
    }

    @ApiOperation("单个渠道授权保存")
    @RequestMapping(value = "singleAgentGrantSave", method = RequestMethod.POST)
    public CommonResult<Long> singleAgentGrantSave(@RequestBody SingleAgentGrantSaveVO singleAgentGrantSaveVO) throws Exception {
        AgentGrantType agentGrantType = agentGrant.saveAgentGrant(singleAgentGrantSaveVO.convertToBo(AgentGrantSaveBO.class));
        return CommonResult.data(agentGrantType.getGrantId());
    }

    @ApiOperation("查询供应商的厂商id集合")
    @RequestMapping(value = "/queryAgentSupplierIds", method = RequestMethod.GET)
    public CommonResult<List<String>> queryAgentSupplierIds(QueryAgentSupplierIdsVO vo) throws Exception {
        return CommonResult.data(agentGrant.queryAgentSupplierIds(vo.getCallCenterCompanyId()));
    }

}
